package com.cucn.ingmall.product.web;

import com.cucn.ingmall.product.service.SkuInfoService;
import com.cucn.ingmall.product.vo.SkuItemVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import javax.annotation.Resource;
import java.util.concurrent.ExecutionException;

/**
 * 商品详情Controller
 *
 * @author KouChaoJie
 * @since: 2022/1/4 16:24
 */
@Controller
@Slf4j
public class ItemController {

    @Resource
    private SkuInfoService skuInfoService;

    /**
     * 当前sku的详情页
     *
     * @param skuId skuid
     * @return sku详情页
     */
    @GetMapping("/{skuId}.html")
    public String skuItem(@PathVariable("skuId") Long skuId, Model model) {

        log.info("准备查询{}详情", skuId);
        SkuItemVO skuItemVO = null;
        try {
            skuItemVO = skuInfoService.item(skuId);
        } catch (Exception e) {
            log.error("查询商品详情出现异常", e);
        }
        model.addAttribute("item", skuItemVO);

        return "item";
    }
}
